package io.kiki.sba.registry.api;

import java.util.concurrent.Executor;


public interface ChannelHandler<T> {


    void connected(Channel channel) throws RemotingException;


    void disconnected(Channel channel) throws RemotingException;


    void messageReceived(Channel channel, T message) throws RemotingException;


    Object messageReply(Channel channel, T message) throws RemotingException;


    void exceptionCaught(Channel channel, T message, Throwable exception) throws RemotingException;


    HandlerType getHandlerType();

    /**
     * return processor request class name
     */
    Class interest();

    /**
     * Select Sync process by reply or Async process by received
     */
    default InvokeType getInvokeType() {
        return InvokeType.SYNC;
    }

    /**
     * specify executor for processor handler
     */
    default Executor getExecutor() {
        return null;
    }


    enum HandlerType {
        LISTENER, PROCESSER
    }

    enum InvokeType {
        SYNC, ASYNC
    }
}
